from enum import Enum


# 一般默认常量值
# Default string value, often used for 'other' or unspecified categories.
defaultStr = 'other'
# Default integer value, typically 0.
defaultInt = 0
# Default status string, often 'undefined'.
defaultStatus = 'undefined'

# Default model name.
defaultModelName = 'default'

# Prefix for SWR (Software Repository) image names.
swrImagePrefix = 'swr.cn-central-221.ovaijisuan.com'

# 是否常量， 如是否能进行训练， 是否能进行体验，是否展示等
# Constant representing a true state (e.g., can be trained, can be experienced, should be displayed).
isTrue = 1
# Constant representing a false state (e.g., cannot be trained, cannot be experienced, should not be displayed).
notTrue = 2

# 共享挂载目录
# Defines the shared mount directory path.
SharedMntDir = '/mnt/publish-data/'


# Base enumeration class providing utility methods for enums.
class TEnum(Enum):
    @classmethod
    # Retrieves the value associated with a given enum key.
    # Args:
    #   key: The name of the enum member.
    #   default: The default value to return if the key is not found. Defaults to defaultInt.
    # Returns:
    #   The value of the enum member or the default value.
    def get_val(cls, key, default=defaultInt):
        try:
            val = cls[key].value
        except Exception:
            val = default
        return val

    @classmethod
    # Checks if an enum key exists within the enumeration.
    # Args:
    #   key: The name of the enum member to check.
    # Returns:
    #   True if the key exists and has a non-None value, False otherwise.
    def exist_key(cls, key):
        if key is None:
            return False
        try:
            val = cls[key].value
            return val is not None
        except Exception:
            return False

    @classmethod
    # Checks if an enum value exists within the enumeration.
    # Args:
    #   val: The value of the enum member to check.
    # Returns:
    #   True if the value exists and corresponds to a non-None key, False otherwise.
    def exist_val(cls, val):
        if val is None:
            return False
        try:
            key = cls(val).name
            return key is not None
        except Exception:
            return False

    @classmethod
    # Retrieves the name (key) of an enum member given its value.
    # Args:
    #   val: The value of the enum member.
    #   default: The default name to return if the value is not found. Defaults to defaultStr.
    # Returns:
    #   The name of the enum member or the default name.
    def get_name(cls, val, default=None):
        if default is None:
            default = defaultStr
        try:
            key = cls(val).name
        except Exception:
            key = default
        return key

    # Overrides the equality operator to allow comparison with other TEnum instances or raw values.
    # Args:
    #   other: The object to compare with.
    # Returns:
    #   True if the values are equal, False otherwise.
    def __eq__(self, other):
        if not isinstance(other, TEnum):
            return other == self.value

        return self.value == other.value